<template>
	<view class="header-section">
		<view class="logo">
			<image src="/static/logo.png" mode="widthFix" />
		</view>
		<view class="search-bar">
			<image class="icon" src="/static/images/search_icon.png" mode="widthFix" />
			<input v-model="searchKey" class="search-input" placeholder="关键词..." />
		</view>
		<button class="search-button" @click="onSearch">搜索</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchKey: ''
			};
		},
		methods: {
			onSearch() {
				if (this.searchKey.trim() !== '') {
					uni.navigateTo({
						url: `/page/search/index?key=${encodeURIComponent(this.searchKey)}`
					});
				} else {
					uni.showToast({
						title: '请输入搜索关键词',
						icon: 'none'
					});
				}
			}
		}
	};
</script>

<style>
	.header-section {
	  display: flex;
	  align-items: center;
	  width: 100%;
	  padding: 10px;
	  box-sizing: border-box;
	  background-color: #fff; /* 确保背景色 */
	}

	.logo {
		flex: 0 0 auto;
		width: 50px;
		/* Adjust the width as needed */
	}

	.search-bar {
		flex: 1;
		display: flex;
		align-items: center;
		background-color: #f3f3f3;
		border-radius: 20px;
		padding: 5px 10px;
		margin: 0 10px;
	}

	.icon {
		width: 20px;
		height: 20px;
		margin-right: 10px;
	}

	.search-input {
		flex: 1;
		border: none;
		outline: none;
		background: transparent;
		font-size: 16px;
	}

	.search-button {
		flex: 0 0 auto;
		padding: 0 10px;
		background-color: #fff;
		color: #000;
		border: 1px solid #fff;
		border-radius: 20px;
		font-size: 16px;
		font-weight: 500;
	}

	.search-button::after {
		border: none;
	}
</style>